export function todo2(arr, pid) {
  var newArr = []
  arr.forEach((item) => {
    // 查找一级根据传进来pid和每一项的pid
    if (item.pid === pid) {
      // 1- 还需要往一级里面追加子children
      var children = todo2(arr, item.id)
      if (children) {
        // 判断二级有不有
        item.children = children
      }
      // 2- 将一级存到返回的数组中
      newArr.push(item)
    }
  })
  return newArr
}
console.log(todo2(arr, ''))
